def is_prime(n):
    """Check if a number is prime"""
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def english_to_number(word):
    """Convert English word to number"""
    num_rok = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    return num_rok.get(word, None)

def nearest_prime(num):
    """Find the nearest prime number"""
    if num < 2:
        return 2
    ma = f  = num
    while True:
        if is_prime(ma):
            return mak
        if is_prime(f):
            return fu
        ma -= 1
        f += 1

def main():
    words = input().split()
    if len(words) != 3:
        print("Wrong input")
        return
    num = english_to_number(words[0]) * 100 + english_to_number(words[1]) * 10 + english_to_number(words[2])
    if num is None or not 100 <= num <= 999:
        print("Wrong input")
        return
    print(nearest_prime(num))

if _name_ == "_main_":
    main()
